export default {
    data() {
        return {
            tableData: [],
            page: 1,
            limit: 10,
            count: 0,
            identity:1,                 //1,超级管理员,2,审核员,3专家,4机构
            region_name_list:[],        //赛区列表
            region_id:'',
            name:''
        }
    },
    
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        that.identity = sessionStorage.getItem("identity");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        that.getList();
        that.regionList();
    },

    //方法
    methods: {
        /**
         * 获取列表
         */
        getList() {
            var that = this;
            that.tableData = [];
            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.user_id = that.user_id;
            if(that.classify_id){
                formData.classify_id = that.classify_id;
            }
            if(that.name){
                formData.key = that.name;
            }
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/User_Identity/index", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body.list) {
                        for (var i in res.body.list) {

                            //作品
                            if(res.body.list[i].video_info.length !== 0){
                                var video_info = "<img src =" + res.body.list[i].video_info.video_pic + " style='height:100px'/ >";
                            }else {
                                var video_info = '未上传';
                            }

                            //是否提交资料
                            if(res.body.list[i].status === 1){
                                var status_text = '<span style="color: #eba6a5;">已提交</span>';
                            }else {
                                var status_text = '<span style="color: #9aca7c;">未提交</span>';
                            }

                            //初审
                            if(res.body.list[i].video_info.is_first_trial === 1){
                                var trial_text = '<span style="color: #9aca7c;">已通过</span>';
                            }else if(res.body.list[i].video_info.is_first_trial === 2){
                                var trial_text = '<p style="color: #eba6a5;">未通过</p><p>原因:'+ res.body.list[i].video_info.first_trial_reason  +'</p>';
                            }else{
                                var trial_text = '<span>待审核</span>';
                            }

                            //专家打分
                            if(res.body.list[i].video_info.is_two_trial === 1){
                                var score_text = '得分('+ res.body.list[i].video_info.total_score +')';
                            }else if(res.body.list[i].video_info.is_two_trial === 2){
                                var score_text = '<p style="color: #eba6a5;">未通过</p><p>原因:'+ res.body.list[i].video_info.two_trial_reason  +'</p>';;
                            }else{
                                var score_text = '待评分';
                            }

                            that.tableData.push({
                                i: i,
                                id: res.body.list[i].id,
                                classify_name: res.body.list[i].classify_name,
                                illustrate: "<p>" + res.body.list[i].real_name + "</p><p>" + res.body.list[i].mobile + "</p><p>"+ res.body.list[i].identity_number + "</p>",
                                video_info: video_info,
                                title: res.body.list[i].video_info.title,
                                status_text: status_text,
                                trial_text: trial_text,
                                score: score_text,
                                total_praise: res.body.list[i].total_praise,
                                region_ranking: res.body.list[i].region_ranking,
                                is_bind: res.body.list[i].is_bind,
                            });
                        }
                        that.count = res.body.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 筛选
         */
        search:function () {
            let that = this;
            that.getList();
        },

        /**
         * 下一页
         * @param currentPage
         */
        handleCurrentChange: function (currentPage) {
            var that = this;
            that.page = currentPage;
        },

        /**
         * 添加
         */
        add: function () {
            var that = this;
            that.$router.push({path: '/seller/student_basic'});
        },

        /**
         * 修改
         * @param id
         */
        edit: function (id) {
            var that = this;
            that.$router.push({path: '/seller/student_basic', query: {student_id: id}});
        },

        /**
         * 删除
         * @param e
         */
        deleteBrand: function (e) {
            var that = this;
            that.$confirm('此操作将永久删除该学生, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.doDelete(e);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //执行删除
        doDelete: function (e) {
            var that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/User_Identity/del", {
                token: that.token,
                id: e
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '删除成功' }`
                    });
                    that.getList();
                },
                function (res) {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body.msg }`
                    });
                });
        },

        /**
         * 赛区列表
         */
        regionList :function () {
            var that = this;
            //请求的数据
            var formData = {};
            formData.token = that.token;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Region/index", formData, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    if(res.body.list){
                        for (var i in res.body.list){
                            that.region_name_list.push ({
                                id:res.body.list[i].id,
                                name:res.body.list[i].name,
                            })
                        }
                    }

                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        }
    }
}